﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExaminationSys.DataAccess;
using ExaminationSys.DataAccess.Entity;
using ExaminationSys.DataAccess.Repository;
using ExaminationSys.Helper;

namespace ExaminationSys
{
    public partial class Downlist : System.Web.UI.Page
    {
        private static readonly StudentService Proxy = ObjectFactory<StudentService>.Create();
        private static readonly TeacherInfoService ProxyTeacherInfo = ObjectFactory<TeacherInfoService>.Create();
        private static readonly NewsTypeService ProxyNewsTypeService = ObjectFactory<NewsTypeService>.Create();
        private static readonly NewsService ProxyNewsService = ObjectFactory<NewsService>.Create();
        private static readonly SectionDownloadService ProxySectionDownload = ObjectFactory<SectionDownloadService>.Create();
        public StringBuilder htmlStr = new StringBuilder();
        public StringBuilder htmlLoginBox = new StringBuilder();
        public List<SectionDownload> SectionDownloadCollection = new List<SectionDownload>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SectionDownloadCollection = ProxySectionDownload.GetPublishList();
                var loginInfo = Session["StudentInfo"] as Student;
                if (loginInfo != null)
                {
                    htmlLoginBox =UIHelpers.BuildLoginBoxHtml(loginInfo);

                }
                else
                {
                    HttpCookie cookie = Request.Cookies["SJEDU_UID"];
                    if (cookie != null)
                    {
                        var uid = cookie["UID"];
                        var pwd = cookie["PWD"];

                        var student = Proxy.Login(uid, pwd);
                        if (student != null)
                        {
                            htmlLoginBox =UIHelpers.BuildLoginBoxHtml(student);
                            Session["StudentInfo"] = student;
                        }
                    }
                }
            }
        }



        private StringBuilder BuildLoginBoxHtml(Student student)
        {
            var sb = new StringBuilder();
            if (student == null) return sb;
            sb.Append("<div class=\"box203\">");
            sb.Append("<div class=\"titles\">");
            sb.Append("<img src=\"images/tit_xx.gif\" alt=\"用户信息\" /></div>");
            sb.Append("<div class=\"conts side-login-on\">");
            sb.Append("<p class=\"tit\">");
            sb.AppendFormat("<span class=\"red\">欢迎您！</span><span>{0}</span>同学</p>", student.UserName);
            sb.Append("<ul>");
            sb.Append("<li><a href=\"#\">个人资料</a></li>");
            sb.Append("<li><a href=\"ChangePassword.aspx\">密码修改</a></li>");
            sb.Append("</ul>");
            sb.Append("<div class=\"button\">");
            sb.Append(
                "<a href=\"StudyCenter.aspx\" id=\"btnStudycenter\"><span style=\"border:1px solid #e3e3e3;color:red;padding:3px;margin:18px\">学习中心</span></a>");
            sb.Append(
                "<input class=\"publicbtn btn-logout\" id=\"btnSignOut\" name=\"\" type=\"button\" value=\"退出\" /></div>");
            sb.Append("</div>");
            sb.Append(" <div class=\"box-bbg\"> </div> </div>");
            return sb;
        }
    }
}